<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 抽离一个延迟执行的函数出来
        function delay(s){
            return new Promise((resolve, reject) => {
                setTimeout(()=>{
                    resolve(`延迟了${s}秒执行`)
                }, s * 1000)
            })
        }

        console.log(delay(1))

        delay(1).then(res => {
            console.log(res)
            return delay(2)
        }).then(res => {
            console.log(res)
            return delay(3)
        }).then(res => {
            console.log(res)
        })


        ;(async () => {
            let res =  await delay(1)
            console.log(res)
            let res2 = await delay(2)
            console.log(res2)
            let res3 = await delay(3)
            console.log(res3)
        })()

        // 每执行一个delay（s）的时候，就会许下一个诺言，就会等待对应的时间，才会走到下一个then的回调

        

    </script>
</body>
</html>